package com.zygh.policeasset.controller;

import com.zygh.policeasset.component.CommonResult;
import com.zygh.policeasset.pojo.ProjectApprovalSteps;
import com.zygh.policeasset.service.ProjectApprovalStepsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping({"/projectapprovalsteps"})
@Api(tags = {"项目审批流程配置"}, description = "ProjectApprovalStepsController")
@RestController
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/controller/ProjectApprovalStepsController.class */
public class ProjectApprovalStepsController {
    @Autowired
    ProjectApprovalStepsService projectApprovalStepsService;

    @RequestMapping(value = {"/findbyType"}, method = {RequestMethod.GET})
    @ApiOperation("根据项目类别查询")
    public Object findbyType(@RequestParam("stepsType") String stepsType) {
        return new CommonResult().success(this.projectApprovalStepsService.findByType(stepsType));
    }

    @RequestMapping(value = {"/add"}, method = {RequestMethod.POST})
    @ApiOperation("新增")
    public Object add(@RequestBody List<ProjectApprovalSteps> projectApprovalSteps) {
        int count = 0;
        for (int i = 0; i < projectApprovalSteps.size(); i++) {
            count = this.projectApprovalStepsService.add(projectApprovalSteps.get(i));
        }
        if (count > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("新增失败");
    }

    @RequestMapping(value = {"/update"}, method = {RequestMethod.POST})
    @ApiOperation("修改")
    public Object update(@RequestBody List<ProjectApprovalSteps> projectApprovalSteps) {
        if (this.projectApprovalStepsService.delete(projectApprovalSteps.get(0).getStepsType()) < 0) {
            return new CommonResult().validateFailed("原审批流程清除失败");
        }
        int count1 = 0;
        for (int i = 0; i < projectApprovalSteps.size(); i++) {
            count1 = this.projectApprovalStepsService.add(projectApprovalSteps.get(i));
        }
        if (count1 > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("修改失败");
    }

    @RequestMapping(value = {"/delete"}, method = {RequestMethod.GET})
    @ApiOperation("删除")
    public Object delete(@RequestParam("stepType") String stepsType) {
        if (this.projectApprovalStepsService.delete(stepsType) > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("删除失败");
    }
}